<?php

/* *
 * 资讯
 */
namespace Common\Model;
use Think\Model;
class CouponModel extends BaseModel {

    public function queryForList($page=null, $map=null) {
        $list = $this->alias("cp")
            ->join("left join __PRODUCT__ p on p.product_id = cp.product_id")
            ->join("left join __COUPON_HOSPITAL__ ch on ch.coupon_hospital_id = cp.coupon_hospital_id")
            ->join("left join __ORDER__ o on o.order_id = cp.order_id")
            ->join("left join __CUSTOMER__ cus on cus.customer_id = o.customer_id")
            ->join("left join __SUPPLIER__ sp on sp.supplier_id = p.supplier_id")
            ->where(getWhereSqlByMap($map))
            ->order(array("o.status" => "asc", "cp.update_time" => "desc", "cp.create_time" => "desc"))
            ->limit($page->firstRow . ',' . $page->listRows)
            ->field("cp.*, p.product_name, ch.coupon_hospital_name, p.image_url, cus.nickname, o.status, o.patient_name, o.doctor_name, o.hospital_name, o.pay_time, o.need_invoice, o.invoice_name, o.invoice_number, o.receive_name, o.receive_contact, o.receive_address,o.express_company, o.delivery_number, o.outstock_time, o.note, sp.supplier_name")
            ->select();

        return $list;

    }

    public function getListCount($map = null) {

        $count = $this->alias("cp")
            ->where(getWhereSqlByMap($map))
            ->count();

        return $count;
    }

}

